package com.smh.a04XmlDemo2;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ParseDemo {
    public static void main(String[] args) throws DocumentException {

        SAXReader saxReader = new SAXReader();
        File file = new File("day32-code\\src\\com\\smh\\a04XmlDemo2\\users.xml");
        Document document = saxReader.read(file);

        ArrayList<User> list = new ArrayList<>();

        Element rootElement = document.getRootElement();
        List<Element> elements = rootElement.elements();
        for (Element element : elements) {
            String name = element.element("name").getText();
            String age = element.element("age").getText();
            String gender = element.element("gender").getText();
            String password = element.element("password").getText();
            User user = new User(name, Integer.parseInt(age), gender, password);
            list.add(user);
        }

        list.forEach(System.out::println);


    }
}
